package com.base.vistter.iframe.inverter.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.base.vistter.iframe.bean.Result;
import com.base.vistter.iframe.entity.SysTeam;
import com.base.vistter.iframe.entity.SysUser;
import com.base.vistter.iframe.exception.IframeException;
import com.base.vistter.iframe.service.SysTeamUserService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/sys/team/user")
public class SysTeamUserController {

    @Resource(name = "sysTeamUserService")
    private SysTeamUserService sysTeamUserService;

    @GetMapping("/unjoin")
    public Result<Page<SysUser>> unjoin(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(value = "pageNum", defaultValue = "10") Integer pageNum, String username, String phone, @RequestParam("teamId") Integer teamId) throws IframeException {
        Page<SysUser> page = Page.of(pageNo, pageNum);
        return Result.ok(sysTeamUserService.unjoin(page, username, phone, teamId));
    }

    @GetMapping("/join")
    public Result<Page<Map<String, Object>>> join(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(value = "pageNum", defaultValue = "10") Integer pageNum, String username, String phone, @RequestParam("teamId") Integer teamId) throws IframeException {
        Page<Map<String, Object>> page = Page.of(pageNo, pageNum);
        return Result.ok(sysTeamUserService.join(page, username, phone, teamId));
    }

    @PostMapping(produces = "application/json;charset=utf-8")
    public Result<Boolean> save(@RequestBody SysTeam sysTeam) throws IframeException {
        return Result.ok(sysTeamUserService.saveTeamUser(sysTeam));
    }

    @DeleteMapping(produces = "application/json;charset=utf-8")
    public Result<Integer> delete(@RequestBody List<String> ids) throws IframeException {
        return Result.ok(sysTeamUserService.delete(ids));
    }

    @DeleteMapping("/{id}")
    public Result<Integer> delete(@PathVariable("id") Integer id) throws IframeException {
        return Result.ok(sysTeamUserService.delete(id));
    }
}
